<template>
    <div class="school">
        <h4>学校姓名:{{name}}</h4>
        <h4>学校地址:{{addr}}</h4>
    </div>
</template>

<script>
    import pubsub from 'pubsub-js'

    export default {
        name : 'School',
        data(){
            return {
                name:'浙大abcdef',
                addr:'浙江杭州',
            }
        },
        mounted() {
            /* this.$bus.$on('hello',(data) => {
                console.log('School 组件接收到数据:',data)
            }) */
            // 订阅消息
            this.pubsubId = pubsub.subscribe('hello',(msgName,msgData)=>{
                console.log('School订阅hello的消息',msgData)
            })
        },
        // 解绑事件
        beforeDestroy(){
            //this.$bus.$off('hello')
            pubsub.unsubscribe(this.pubsubId)
        }
    
    };
</script>

<style scoped lang="less">
    .school{
        background-color: skyblue;
    }
</style>
